/*
 *  GameWorld.h
 *  sfmltest1
 *
 *  Created by Steven Hamilton on 21/06/09.
 *  Copyright 2009 __MyCompanyName__. All rights reserved.
 *
 */
#ifndef __GAMEWORLD_H__
#define __GAMEWORLD_H__

#include "defines.h"
#include "Creature.h"
#include "DisplayManager.h"
#include "Map.h"
#include "Position.h"
#include "SquadAI.h"
#include "AnimManager.h"
#include <vector>

class ScreenTile;

class GameWorld {
private:
	GameWorld();
	GameWorld(const GameWorld&);
	GameWorld& operator=(const GameWorld&);
	void generatePlayers();
	void generateItems();

    std::vector<Creature> creatures;
	std::vector<Creature>::iterator creatureIt;
	std::vector<Item> items;
	std::vector<Item>::iterator itemIt;

    int objectIdIndex;
public:
	~GameWorld();
    int objectId;
    
    void initWorld();

	static GameWorld& instance(){
		static GameWorld world;
		return world;
	}
	
    //console support
    std::vector<std::string> consoleBuffer;
	void sendMessageToConsole(std::string);
	void clearConsole();
	
	//global game stats
	int level;
	int finalLevel;
    event_t checkMatchStatus(event_t);

    //creature Big List management & queries
	void regeneratePlayers();
    int getObjectId();
    void addCreature(Creature&);
    void delCreature(Creature*);
    std::vector<Creature*> getCreatures(faction_t);
    std::vector<Creature*> getCreatures(faction_t,bool mapStatus);
    std::vector<Creature*> getCreatures(bool mapStatus);
    void toggleCreatureToMap(Creature*);
	int getNumberOfCreatures(faction_t,bool mapStatus);

    //item Big List management
    Item * generateItem(itemType_t, int ownerId);
	void addItem(Item&);
	Item * getItemforObjectId(int objectId);
    std::vector<Item*> getItems(int objectId);
    std::vector<Item*> getItems(itemType_t);
    std::vector<Item*> getItems(itemType_t,bool mapStatus);
    std::vector<Item*> getItems(bool mapStatus);
    void toggleItemToMap(Item*);
    int getNumberOfItems(bool mapStatus);

	// map functions
	Map map;
	void generateMap();
	void updateMapVisibility();
	std::string getVisibleElementNameAt(Position);
	bool isTileOccupied(Position);
	bool isTileBlocked(Position);
	
	// action functions
	void attack(Creature*);
	void damageEntityAtPosition(Position, Item&);
    void setFiringMode(firingMode_t);
    firingMode_t firingMode;
    int firingCost;

	//action subroutines
	double targetAngle(Position, Position);
	double modifyAimAngle(Creature*,double);
	Position fireAtAngle(Creature*,double);
	
	// selection functions
	void initSelectionCursor();
	void endSelectionCursor();
	void moveSelectionCursor(int);
	void moveSelectionCursorTo(Position);
	Position target;
	gfxId_t selectionGfxId;
	void targetNextEnemy(Creature*);
            
	//player functions
	Creature * selectedPlayer;
	void positionPlayers();
	void selectFirstPlayer();
	void selectNextPlayer();
	void selectLivePlayer();
	void initPlayers();
	void resetPlayers();

    //AI
	SquadAI squadAI;

	//animation - refactor this out somehow
	AnimManager	anim;

};



#endif
